package com.wicket.okrframework.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrframework.base.service.MStationTypeService;
import com.wicket.okrframework.base.service.dto.req.BatchQueryStationTypeReq;
import com.wicket.okrframework.base.service.dto.req.QueryStationTypeDetailReq;
import com.wicket.okrframework.base.service.dto.req.QueryStationTypeListReq;
import com.wicket.okrframework.common.dto.FieldInfo;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.StationTypeMapper;
import com.wicket.okrframework.dal.po.mbg.Station;
import com.wicket.okrframework.dal.po.mbg.StationType;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.wicket.okrframework.base.service.dto.req.BatchDeleteStationTypeTestDataReq;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MStationTypeServiceImpl
        extends ServiceImpl<StationTypeMapper, StationType>
        implements MStationTypeService {

    @Autowired
    StationTypeMapper stationTypeMapper;

    /**
   * 1-3-04批量查询岗位类型[1651]
   * gen by moon at 10/16/2022, 11:07:15 AM
   */
 @Trace(operationName = "1-3-04批量查询岗位类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<StationType>  batchQueryStationType(BatchQueryStationTypeReq reqDto) {
     
        try {
            QueryWrapper<StationType> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if(reqDto.getOrgStationTypeList()==null || reqDto.getOrgStationTypeList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("station_type_id", reqDto.getOrgStationTypeList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(StationType.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(StationType.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(StationType.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<StationType>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

    /**
   * 1-3-04查询岗位类型列表[142]
   * gen by moon at 10/16/2022, 11:07:15 AM
   */
 @Trace(operationName = "1-3-04查询岗位类型列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<StationType>  queryStationTypeList(QueryStationTypeListReq reqDto) {
     
        try {
            QueryWrapper<StationType> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(StationType.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(StationType.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(StationType.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("order_number");
queryWrapper.orderByDesc("operate_time");
            return ((List<StationType>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

    /**
   * 1-3-04查询岗位类型详情[141]
   * gen by moon at 10/16/2022, 11:07:14 AM
   */
 @Trace(operationName = "1-3-04查询岗位类型详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  StationType  queryStationTypeDetail(QueryStationTypeDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<StationType> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<StationType> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                StationType retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }

    /**
   * 1-3-04删除岗位类型[140]
   * gen by moon at 10/16/2022, 11:07:13 AM
   */
 @Trace(operationName = "1-3-04删除岗位类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteStationType(String stationTypeId ) {
     
      return super.removeById(stationTypeId);
  }

    /**
   * 1-3-04修改岗位类型[139]
   * gen by moon at 10/16/2022, 11:07:13 AM
   */
 @Trace(operationName = "1-3-04修改岗位类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateStationType(StationType stationType) {
     stationType.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
stationType.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(stationType!=null && stationType.getSubjectLifeCycle()!=null && stationType.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             stationType.setOperateTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(stationType!=null && stationType.getSubjectLifeCycle()!=null && stationType.getSubjectLifeCycle().equals("ARCHIVING")) {
              stationType.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
        return super.updateById(stationType);
  }

    /**
   * 1-3-04新增岗位类型[138]
   * gen by moon at 10/16/2022, 11:07:12 AM
   */
 @Trace(operationName = "1-3-04新增岗位类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addStationType(StationType stationType) {
     stationType.setStationTypeId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
stationType.setStationTypeCode("ST");//CUSTOM_CONVENTION
stationType.setBatchEndTime(CommonFunctionHelper.getFutureTime());//FUTURE_CURRENT_TIME
stationType.setSubjectLifeCycle("EDITING");
stationType.setIsArchive("FALSE");
stationType.setAchivngType("NOT_ARCHIVE");
stationType.setIsEditing("TRUE");
stationType.setIsUpdate("TRUE");
stationType.setUpdateStatus("NEW");
stationType.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
stationType.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
stationType.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
stationType.setIsValid("FALSE");
stationType.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
stationType.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(stationType)){
        return stationType.getStationTypeId();
     }else {
        return "-1";
     }
    
  }
/**
   * M1查询岗位类型测试列表[4915]
   * gen by moon at 10/16/2022, 11:07:16 AM
   */
 @Trace(operationName = "M1查询岗位类型测试列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<StationType>  queryStationTypeTestDataList(StationType stationType) {
     
        try {
            QueryWrapper<StationType> queryWrapper = new QueryWrapper<>();
            
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(stationType);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(StationType.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(StationType.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(StationType.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<StationType>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * M1批量删岗位类型测试[4917]
   * gen by moon at 10/16/2022, 11:07:16 AM
   */
 @Trace(operationName = "M1批量删岗位类型测试")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteStationTypeTestData(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }
}
